package com.sharding.issuse.Controller;


import com.sharding.issuse.Service.TestService;
import com.sharding.issuse.dao.RobotCaseMapper;
import com.sharding.issuse.dao.RobotContactMapper;
import com.sharding.issuse.model.RobotContact;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * 定时消息扫描
 *
 * @author lxh
 * @create 2017-06
 */
@RestController
public class TestController {
    private static Log logger = LogFactory.getLog(TestController.class);

    @Autowired
    private RobotContactMapper robotContactMapper;
    @Autowired
    private RobotCaseMapper robotCaseMapper;
    @Autowired
    private TestService testService;

    @RequestMapping(value = "select", method = RequestMethod.GET)
    @ResponseBody
    //不加事物时全部执行成功
    public Object select() {
        testService.testSpringTransaction();
        return null;
    }

    @RequestMapping(value = "nosdSelect", method = RequestMethod.GET)
    @ResponseBody
    public Object noShardingTableSelect() {
        try {
            robotCaseMapper.getCaseStatusBanch(new HashMap<>());
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("未分表的表联合查询失败");
        }
        return null;
    }

    @RequestMapping(value = "updateSdTable", method = RequestMethod.GET)
    @ResponseBody
    public Object updateSdTable() {
        RobotContact contactEntity1 = robotContactMapper.selectContactInfoByCon(5165L, 86196476572602368L);
        robotContactMapper.updateByPrimaryKeySelective(contactEntity1);
        return null;
    }

    @RequestMapping(value = "testRollBack", method = RequestMethod.GET)
    public void testRollBack() {
        testService.tetsRollBack();
    }

    @RequestMapping(value = "testNoRollBack", method = RequestMethod.GET)
    public void testNoRollBack() {
        testService.tetsNoRollBack();
    }

}
